Attribute VB_Name = "modTD"
'---------------------------------------------------------------------------------------
'Module : modTD
'Date   : 03/07/2005
'Author : Joseph Weir
'Purpose: Copy of frmShip routines for TD transactions.
'
' 2005-04-28, JFW, Vantreight, corrections and testing.
' 2006-12-18, JFW, Child shipment IRS number saved to Client DB.
' 2007-05-15, JFW, TD MPS with FXRS 840.  New boolean TDChild for logic flow.
'
'---------------------------------------------------------------------------------------
'

Option Explicit

Public g_frmTD As frmTD
Public g_frmTDAdd As frmTDAdd
Public g_frmTDAutoClose As frmTD
Public g_frmTDAutoOpen As frmTD

Public g_str542 As String
Public g_blnTDInProgress As Boolean                'Set to True when TD is selected
Public g_blnTDChild As Boolean                     'Set to True when TD is selected
Public g_blnTDConfirm As Boolean                   'Set to True when confirming a TD shipment
Public g_blnTDCreate As Boolean                    'Set to True when adding a TD shipment
Public g_strTDOpenShip As String                   'Current Open Ship Index
Public g_strTDMasterTrkNbr As String
Public g_dteTDDate As Date

'---------------------------------------------------------------------------------------
' Procedure : BuildTDCreateTrans
' DateTime  : 10/26/2004
' Purpose   : Builds an TD MAWB Transaction
'---------------------------------------------------------------------------------------
'
Public Function BuildTDCreateTrans() As String
    Dim strTrans As String
    
    On Error GoTo EH
    g_strErrorLocation = "modMain:BuildTDCreateTrans"
    
    strTrans = ""
    
    TransactionBuilder strTrans, 0, "020"                   'Trans type
    TransactionBuilder strTrans, 1, "TD MAWB CREATE"       'TransID
    ' 10,"128652841"
    ' TransactionBuilder strTrans, 20, g_str20                'Bill-To Acct#
    If g_frmTDAdd.f24 <> Date Then
        TransactionBuilder strTrans, 24, Format(g_frmTDAdd.f24 & "", "YYYYMMDD")                'Ship date
        g_str24 = Format(g_frmTDAdd.f24 & "", "YYYYMMDD")
    End If
    If g_frmTDAdd.f25 <> "" Then
        TransactionBuilder strTrans, 25, g_frmTDAdd.f25 & ""       'Reference
    End If
    TransactionBuilder strTrans, 50, g_frmTDAdd.tdReturn("f50") & ""            'Recip Country
    If g_frmTDAdd.f66 <> "" Then
        TransactionBuilder strTrans, 66, g_frmTDAdd.f66 & ""
    End If
    If g_frmTDAdd.f67 <> "" Then
        TransactionBuilder strTrans, 67, g_frmTDAdd.f67 & ""
    End If
    TransactionBuilder strTrans, 68, g_frmTDAdd.f68 & ""                'Currency Type
    TransactionBuilder strTrans, 70, Left(g_frmTDAdd.f70 & "", 1)               'Duty/Tax Pay Type
    TransactionBuilder strTrans, 71, g_frmTDAdd.f71                'Duty/Tax Acct#
    TransactionBuilder strTrans, 72, Left(g_frmTDAdd.f72 & "", 1)               'Terms of Sale
    TransactionBuilder strTrans, 74, g_frmTDAdd.tdReturn("f50")                'Country of Ultimate Dest
    TransactionBuilder strTrans, 75, g_frmTDAdd.f75 & ""                'Weight type
    
    TransactionBuilder strTrans, 79, "Description of contents"
    TransactionBuilder strTrans, 80, "CA"
    

    ' TransactionBuilder strTrans, 117, g_str117              'Shipper country
    ' 2007-05-30, JFW, Why should the Ship screen affect CI/CCI
    ' If frmShip.optCommodities.Value Then
    If g_frmTDAdd.f113.Value = 1 Then
        TransactionBuilder strTrans, 113, "Y"              'CI Flag, this is CCI when on master
        If g_str538 <> "" Then
            TransactionBuilder strTrans, 538, g_str538                                  'CI Printer UNC
        End If
    Else
        TransactionBuilder strTrans, 113, "N"              'CI Flag, this is CCI when on master
    End If
    
    ' IOR
    TransactionBuilder strTrans, 169, g_frmTDAdd.tdIOR("f50") & ""
    TransactionBuilder strTrans, 170, g_frmTDAdd.tdIOR("f12") & ""
    TransactionBuilder strTrans, 171, g_frmTDAdd.tdIOR("f11") & ""
    TransactionBuilder strTrans, 172, g_frmTDAdd.tdIOR("f13") & ""
    TransactionBuilder strTrans, 173, g_frmTDAdd.tdIOR("f14") & ""
    TransactionBuilder strTrans, 174, g_frmTDAdd.tdIOR("f15") & ""
    TransactionBuilder strTrans, 175, g_frmTDAdd.tdIOR("f16") & ""
    TransactionBuilder strTrans, 176, g_frmTDAdd.tdIOR("f17") & ""
    TransactionBuilder strTrans, 178, g_frmTDAdd.tdIOR("f18") & ""
    TransactionBuilder strTrans, 180, g_frmTDAdd.tdIOR("CustID") & ""
    
    TransactionBuilder strTrans, 498, frmSetup.f498 & ""         'Meter #
    TransactionBuilder strTrans, 541, "YNNNNNNNN"           'Open Ship Flag
    
    g_str542 = Format(Now, "ddHHnnss")                      'Open ship index
    TransactionBuilder strTrans, 542, g_str542              'Open ship index
    
    TransactionBuilder strTrans, 1090, g_str68              'Currency
    If g_str1139 <> "" Then
        TransactionBuilder strTrans, 1139, g_str1139        'Sender IRS
    End If
    
                                    ' BSO no-no, 1174,"Y"
                                '    TransactionBuilder strTrans, 1179, ""
                                '    TransactionBuilder strTrans, 1180, "Broker Company"
                                '    TransactionBuilder strTrans, 1181, "Broker Address Line 1"
                                '    TransactionBuilder strTrans, 1182, "Broker Address Line 2"
                                '    TransactionBuilder strTrans, 1183, "New York"
                                '    TransactionBuilder strTrans, 1184, "NY"
                                '    TransactionBuilder strTrans, 1185, "10018"
                                '    TransactionBuilder strTrans, 1186, "US"
                                    ' TransactionBuilder strTrans, 1187, "BSO001"
    
    TransactionBuilder strTrans, 1274, "82"                 'Service Type
    
    TransactionBuilder strTrans, 1297, g_str1297            'Customer Inv #
    
    ' TransactionBuilder strTrans, 1355, g_str1355            'IOR Facility Code
    ' TransactionBuilder strTrans, 1349, g_str1349            'AES Filing Status
    
    TransactionBuilder strTrans, 1358, g_str1358            'ITN/FTSR
    ' Trying to get something in FSMS export permit
    ' TransactionBuilder strTrans, 1399, "12345"
    TransactionBuilder strTrans, 1483, g_frmTDAdd.f1483 & ""       ' SCAC
    TransactionBuilder strTrans, 1484, IIf(g_frmTDAdd.f1484 & "", "Y", "N")    ' FedEx linehaul
    If g_frmTDAdd.f1484 Then
        TransactionBuilder strTrans, 1498, Left(g_frmTDAdd.f1498 & "", 1)   ' Payment type
        TransactionBuilder strTrans, 1500, g_frmTDAdd.f1500 & ""    ' Acct #
        ' Else
        ' TransactionBuilder strTrans, 1502, "N"
    End If
    
    ' TD return
    TransactionBuilder strTrans, 1485, g_frmTDAdd.tdReturn("f12") & ""
    TransactionBuilder strTrans, 1486, g_frmTDAdd.tdReturn("f11") & ""
    TransactionBuilder strTrans, 1487, g_frmTDAdd.tdReturn("f13") & ""
    TransactionBuilder strTrans, 1488, g_frmTDAdd.tdReturn("f14") & ""
    TransactionBuilder strTrans, 1489, g_frmTDAdd.tdReturn("f15") & ""
    TransactionBuilder strTrans, 1490, g_frmTDAdd.tdReturn("f16") & ""
    TransactionBuilder strTrans, 1491, g_frmTDAdd.tdReturn("f17") & ""
    TransactionBuilder strTrans, 1492, g_frmTDAdd.tdReturn("f18") & ""
    
    If g_frmTDAdd.f1502Y Then
        ' Tower group broker
        TransactionBuilder strTrans, 1502, "Y"
        TransactionBuilder strTrans, 1546, Left(g_frmTDAdd.f1546 & "", 1)   ' Payment type
        TransactionBuilder strTrans, 1503, g_frmTDAdd.f1503 & ""    ' Acct #
        ' Else
        ' TransactionBuilder strTrans, 1502, "N"
    End If
    
    TransactionBuilder strTrans, 1666, g_frmTDAdd.tdReturn("f15") & ""
    
    TransactionBuilder strTrans, 99, ""                     'End of Transaction
    
    ' debugprint "BuildTDCreateTrans", strTrans
    
    BuildTDCreateTrans = strTrans
    
    Exit Function
EH:
    MsgBox Err.Description, vbCritical, g_strErrorLocation
End Function
'

'---------------------------------------------------------------------------------------
' Procedure : BuildTDConfirmTrans
' DateTime  : 10/26/2004
' Purpose   : Builds an TD Confirm Transaction
'---------------------------------------------------------------------------------------
'
Public Function BuildTDConfirmTrans(TDMeter As String, TDOpenShip As String) As String
    Dim strTrans As String
    
    On Error GoTo EH
    g_strErrorLocation = "modMain:BuildTDConfirmTrans"
    
    strTrans = ""
    With g_frmTD
        TransactionBuilder strTrans, 0, "020"                   'Trans type
        TransactionBuilder strTrans, 1, "TD MAWB CONFRM"       'TransID
        ' TransactionBuilder strTrans, 50, .grdTD.Columns(3)     'Recip Country
        TransactionBuilder strTrans, 498, TDMeter         'Meter #
        TransactionBuilder strTrans, 541, "NNNNNYNNY"           'Open Ship Flag
        TransactionBuilder strTrans, 542, TDOpenShip              'Open ship index
    End With
    
    TransactionBuilder strTrans, 99, ""                 'End of Transaction
    
    BuildTDConfirmTrans = strTrans
    
    Exit Function
EH:
    MsgBox Err.Description, vbCritical, g_strErrorLocation
End Function


'---------------------------------------------------------------------------------------
' Procedure : BuildCRNDeleteTrans
' DateTime  : 11/1/2004
' Purpose   : Deletes a trk#
'---------------------------------------------------------------------------------------
'
Public Function BuildTDCDeleteTrans(ByVal strTrackNum As String, Optional ByVal strOpenShip As String = "", Optional ByVal strAccount As String = "") As String
    Dim strTrans As String
    Dim rs As New ADODB.Recordset
    
    On Error GoTo EH
    g_strErrorLocation = "modFXRSTransactions:BuildTDCDeleteTrans"
    
    If strOpenShip = "" Then
        rs.Open "select OpenShipIndex, g_str29, g_str10 from TD where g_str29 = '" & strTrackNum & "'", g_connFSMSClient
        If Not rs.BOF Then
            strOpenShip = rs!OpenShipIndex
            strAccount = rs!g_str10
        End If
    End If
    
    'Save the trk# to global var
    g_str29 = strTrackNum
    
    'Set IPD flag to True
    g_blnTDInProgress = True
    
    strTrans = ""
    TransactionBuilder strTrans, 0, "020"                   'Transaction type
    TransactionBuilder strTrans, 1, "TD TDC DELETE"       'Transaction ID
    TransactionBuilder strTrans, 29, g_str29                'Tracking #
    
    ' 2010-11-03, JFW, Fix screen location/meter taken for delete
    ' TransactionBuilder strTrans, 498, g_str498              'Meter #
    TransactionBuilder strTrans, 10, strAccount
    TransactionBuilder strTrans, 541, "NNNNNNYNN"           'Open Ship Flags
    TransactionBuilder strTrans, 542, strOpenShip
    TransactionBuilder strTrans, 99, ""                     'End of Transaction
    
    BuildTDCDeleteTrans = strTrans
    
    Exit Function
EH:
     MsgBox Err.Description, vbCritical, g_strErrorLocation

End Function


'---------------------------------------------------------------------------------------
' Procedure : BuildTDDeleteTrans
' DateTime  : 10/26/2004
' Purpose   : Builds an TD Delete Shipment Transaction
'---------------------------------------------------------------------------------------
'
Public Function BuildTDDeleteTrans(TDMasterTrkNbr As String, TDMeter As String, TDOpenShip As String) As String
    Dim strTrans As String
    
    On Error GoTo EH
    g_strErrorLocation = "modMain:BuildTDDeleteTrans"
    
    strTrans = ""
    TransactionBuilder strTrans, 0, "020"                                   'Trans type
    TransactionBuilder strTrans, 1, "TD MAWB DELETE"   'TransID
    TransactionBuilder strTrans, 29, TDMasterTrkNbr                    'MAWB Trk#
    ' TransactionBuilder strTrans, 50, .grdTD.Columns(3)     'Recip Country
    TransactionBuilder strTrans, 498, TDMeter         'Meter #
    TransactionBuilder strTrans, 541, "NNNNNNNYN"           'Open Ship Flag
    TransactionBuilder strTrans, 542, TDOpenShip     'Open ship index
    TransactionBuilder strTrans, 99, ""                 'End of Transaction
    BuildTDDeleteTrans = strTrans
    
    Exit Function
EH:
    MsgBox Err.Description, vbCritical, g_strErrorLocation
End Function


'---------------------------------------------------------------------------------------
' Module    : ChangeTDStatus
' DateTime  : 10/28/2004
' Author    : Chris Elwell
' Purpose   : Changes a TD status to Confirmed or Deleted in the TD table.
' Call from : g_clsParserShip_ParseComplete()
'---------------------------------------------------------------------------------------
'
Private Sub ChangeTDStatus(ByVal strTrkNum As String, ByVal strStatus As String)
    Dim strQuery As String
    Dim Start As Long
    Dim rsTrkNum As New ADODB.Recordset
    
    On Error GoTo EH
    g_strErrorLocation = "frmShip:ChangeTDStatus"
    
    strQuery = "UPDATE TD SET [TDStatus] = " & SingleQuotes(strStatus) & " WHERE g_str1123 = " & SingleQuotes(strTrkNum)
    g_connFSMSClient.Execute strQuery
    If strStatus = "Deleted" Then
        strQuery = "UPDATE TD SET [Status] = " & SingleQuotes(strStatus) & " WHERE g_str1123 = " & SingleQuotes(strTrkNum)
        g_connFSMSClient.Execute strQuery
    End If
    
    'This one second delay allows update to complete before query is re-run.
    If g_blnDeletesComplete Then
        Start = Timer
        Do While Timer < Start + 1
            DoEvents
        Loop
    End If
    
    Exit Sub
EH:
     MsgBox Err.Description, vbCritical, g_strErrorLocation
End Sub


'---------------------------------------------------------------------------------------
' Module    : ChangeTDCStatus
' DateTime  : 10/28/2004
' Author    : Chris Elwell
' Purpose   : Changes a TDC status to Deleted in the TD table.
' Call from : g_clsParserShip_ParseComplete()
'---------------------------------------------------------------------------------------
'
Private Sub ChangeTDCStatus(ByVal strTrkNum As String)
    Dim rsQuery As String
    Dim Start As Long
    
    On Error GoTo EH
    g_strErrorLocation = "frmShip:ChangeTDCStatus"
    
    rsQuery = "UPDATE TD SET [Status] = 'Deleted' WHERE g_str29 = " & SingleQuotes(strTrkNum)

    g_connFSMSClient.Execute rsQuery
    
    'This one second delay allows update to complete before query is re-run.
    If g_blnDeletesComplete Then
        Start = Timer
        Do While Timer < Start + 1
            DoEvents
        Loop
    End If
    
    Exit Sub
EH:
     MsgBox Err.Description, vbCritical, g_strErrorLocation
End Sub


'---------------------------------------------------------------------------------------
' Module    : SaveTDShipment
' DateTime  : 3/17/2004
' Author    : Chris Elwell
' Purpose   : Store TD shipment fields to database
' Call from : g_clsParserShip_ParseComplete()
'---------------------------------------------------------------------------------------
'
Public Sub SaveTDShipment(ByVal strTrkNum As String, ByVal blnIsCreate As Boolean, Optional ByVal strMasterTrkNum As String)
    Dim strInsertQuery As String
    Dim rsTD As New ADODB.Recordset
    Dim strQuery As String
    
    On Error GoTo EH
    'g_strErrorLocation = "frmShip:SaveTDShipment"
        
    '        If Not blnIsCreate Then
    '            strQuery = "SELECT g_str1297 FROM TD WHERE TDStatus = 'Open' And g_str1355 = " & SingleQuotes(g_str1355)
    '            rsTD.Open strQuery, g_connFSMSClient, adOpenStatic, adLockOptimistic
    '
    '            g_str1297 = rsf1297!g_str1297
    '        End If
    
    strInsertQuery = "INSERT INTO TD ( OpenShipIndex, TDStatus, MAWB, " _
        & "g_str29, g_str1123, g_str25, g_str50, g_str10, g_str24, " _
        & "ReturnAddressID, IORID, f66, f67, f68, f70, f71, f72, f75, " _
        & "f113, f119, f1358, f1483, f1484, f1498, f1500, f1502, f1503, f1546, " _
        & "Status, ProcessTime, LocationName, [Transaction] ) "
    
'    If GetClientDatabaseType <> "Access" Then
'        strInsertQuery = Replace(strInsertQuery, "Transaction", """Transaction""")
'    End If
    
    
    strInsertQuery = strInsertQuery + " VALUES ( "
    If g_str542 <> "" Then
        strInsertQuery = strInsertQuery + SingleQuotes(g_str542) + ","
    ElseIf g_strTDOpenShip <> "" Then
        strInsertQuery = strInsertQuery + SingleQuotes(g_strTDOpenShip) + ","
    End If
    strInsertQuery = strInsertQuery + SingleQuotes("Open") + ","
    'If it's a MAWB Create, set MAWB to 1
    strInsertQuery = strInsertQuery + "1,"
    strInsertQuery = strInsertQuery + SingleQuotes(strTrkNum) + ","
    strInsertQuery = strInsertQuery + SingleQuotes(strTrkNum) + ","
    strInsertQuery = strInsertQuery + SingleQuotes(g_frmTDAdd.f25) + ","
    strInsertQuery = strInsertQuery + SingleQuotes(g_frmTDAdd.tdReturn("f50")) + ","
    strInsertQuery = strInsertQuery + SingleQuotes(g_str10) + ","
    strInsertQuery = strInsertQuery + SingleQuotes(Format(g_dteTDDate, "YYYYMMDD")) + ","
    
    strInsertQuery = strInsertQuery + SingleQuotes(g_frmTDAdd.cboReturn) + ","
    strInsertQuery = strInsertQuery + SingleQuotes(g_frmTDAdd.cboIOR) + ","
    strInsertQuery = strInsertQuery + SingleQuotes(g_frmTDAdd.f66) + ","
    strInsertQuery = strInsertQuery + SingleQuotes(g_frmTDAdd.f67) + ","
    strInsertQuery = strInsertQuery + SingleQuotes(g_frmTDAdd.f68) + ","
    strInsertQuery = strInsertQuery + SingleQuotes(Left(g_frmTDAdd.f70, 1)) + ","
    strInsertQuery = strInsertQuery + SingleQuotes(g_frmTDAdd.f71) + ","
    strInsertQuery = strInsertQuery + SingleQuotes(Left(g_frmTDAdd.f72, 1)) + ","
    strInsertQuery = strInsertQuery + SingleQuotes(g_frmTDAdd.f75) + ","
    strInsertQuery = strInsertQuery + SingleQuotes(IIf(g_frmTDAdd.f113, "Y", "N")) + ","
    strInsertQuery = strInsertQuery + SingleQuotes(g_frmTDAdd.f119) + ","
    strInsertQuery = strInsertQuery + SingleQuotes(g_frmTDAdd.f1358) + ","
    strInsertQuery = strInsertQuery + SingleQuotes(g_frmTDAdd.f1483) + ","
    strInsertQuery = strInsertQuery + SingleQuotes(IIf(g_frmTDAdd.f1484, "Y", "N")) + ","
    strInsertQuery = strInsertQuery + SingleQuotes(Left(g_frmTDAdd.f1498, 1)) + ","
    strInsertQuery = strInsertQuery + SingleQuotes(g_frmTDAdd.f1500) + ","
    strInsertQuery = strInsertQuery + SingleQuotes(IIf(g_frmTDAdd.f1502Y, "Y", "N")) + ","
    strInsertQuery = strInsertQuery + SingleQuotes(g_frmTDAdd.f1503) + ","
    strInsertQuery = strInsertQuery + SingleQuotes(Left(g_frmTDAdd.f1546, 1)) + ","

    strInsertQuery = strInsertQuery + "'Shipped', "
    
    If GetClientDatabaseType = "Access" Then
        strInsertQuery = strInsertQuery + "#" + CStr(Now) + "#, "
    Else
        strInsertQuery = strInsertQuery + "'" + CStr(Now) + "', "
    End If
    
    strInsertQuery = strInsertQuery + SingleQuotes(frmShip.cboLocationName(0)) + ", "
    strInsertQuery = strInsertQuery + SingleQuotes(Left(g_strRepeatTrans, 512)) + ")"
    
    DebugPrint "SaveTDShipment, " & strInsertQuery
    
    g_connFSMSClient.Execute strInsertQuery
    
    g_strTDOpenShip = g_str542
    
    g_strTDMasterTrkNbr = strTrkNum
    g_dteTDDate = CDate(g_frmTDAdd.f24)
    
    g_clsReg.SetRegistryValue "TDMasterShipmentID", g_strTDMasterTrkNbr, REG_SZ
    g_clsReg.SetRegistryValue "TDMasterShipmentDate", Format(g_dteTDDate, "yyyy-mm-dd"), REG_SZ
    g_clsReg.SetRegistryValue "TDOpenShipIndex", g_strTDOpenShip, REG_SZ
    
    frmShip.DomIntlScreenLayout
    frmShip.f24 = g_dteTDDate
        
Release:
    If rsTD.State = adStateOpen Then rsTD.Close
    Set rsTD = Nothing
    
    Exit Sub
EH:
     MsgBox Err.Description, vbCritical, "frmShip:SaveTDShipment"

End Sub



'---------------------------------------------------------------------------------------
' Module    : SaveTDCShipment
' DateTime  : 3/17/2004
' Author    : Chris Elwell
' Purpose   : Store TD shipment fields to database
' Call from : g_clsParserShip_ParseComplete()
'---------------------------------------------------------------------------------------
'
Public Sub SaveTDCShipment(ByVal strTrkNum As String, ByVal blnIsCreate As Boolean, Optional ByVal strMasterTrkNum As String)
    Dim strInsertQuery As String
    Dim rsTD As New ADODB.Recordset
    Dim strQuery As String
    
    On Error GoTo EH
    g_strErrorLocation = "frmShip:SaveTDCShipment"
    
    ' 2006-12-18, JFW, Child shipment IRS number
    strInsertQuery = "INSERT INTO TD ( OpenShipIndex, TDStatus, MAWB, " _
        & "g_str29, g_str1123, g_str25, g_str50, g_str10, g_str24, " _
        & "g_str3056, g_str3057, g_str11, g_str12, g_str13, g_str15, g_str16, g_str17, " _
        & "g_str1274, g_str116, f1358, " _
        & "Status, ProcessTime ) "
    strInsertQuery = strInsertQuery + " VALUES ( "
    If g_str542 <> "" Then
        strInsertQuery = strInsertQuery + SingleQuotes(g_str542) + ","
    ElseIf g_strTDOpenShip <> "" Then
        strInsertQuery = strInsertQuery + SingleQuotes(g_strTDOpenShip) + ","
    End If
    strInsertQuery = strInsertQuery + SingleQuotes("Open") + ","
    'If it's a MAWB Create, set MAWB to 1
    strInsertQuery = strInsertQuery + "0,"
    strInsertQuery = strInsertQuery + SingleQuotes(strTrkNum) + ","
    strInsertQuery = strInsertQuery + SingleQuotes(g_strTDMasterTrkNbr) + ","
    strInsertQuery = strInsertQuery + SingleQuotes(g_str25) + ","
    If g_str50 <> "" Then
        strInsertQuery = strInsertQuery + SingleQuotes(g_str50) + ","
    Else
        strInsertQuery = strInsertQuery + SingleQuotes("US") + ","
    End If
    strInsertQuery = strInsertQuery + SingleQuotes(g_str10) + ","
    strInsertQuery = strInsertQuery + SingleQuotes(Format(g_dteTDDate, "YYYYMMDD")) + ","
    
    strInsertQuery = strInsertQuery + SingleQuotes(g_str3056) + ","
    strInsertQuery = strInsertQuery + SingleQuotes(g_str3057) + ","
    strInsertQuery = strInsertQuery + SingleQuotes(Left(g_str11, 35)) + ","
    strInsertQuery = strInsertQuery + SingleQuotes(Left(g_str12, 35)) + ","
    strInsertQuery = strInsertQuery + SingleQuotes(Left(g_str13, 35)) + ","
    strInsertQuery = strInsertQuery + SingleQuotes(Left(g_str15, 35)) + ","
    strInsertQuery = strInsertQuery + SingleQuotes(Left(g_str16, 14)) + ","
    strInsertQuery = strInsertQuery + SingleQuotes(Left(g_str17, 10)) + ","
    strInsertQuery = strInsertQuery + SingleQuotes(g_str1274) + ","
    strInsertQuery = strInsertQuery + SingleQuotes(g_str116) + ","
    
    ' 2006-12-18, JFW, Child shipment IRS number
    strInsertQuery = strInsertQuery + SingleQuotes(g_str118) + ","
    
    strInsertQuery = strInsertQuery + "'Shipped',"
    
    If GetClientDatabaseType = "Access" Then
        strInsertQuery = strInsertQuery + "#" + CStr(Now) + "#)"
    Else
        strInsertQuery = strInsertQuery + "'" + CStr(Now) + "')"
    End If
    
    g_connFSMSClient.Execute strInsertQuery
    
Release:
    If rsTD.State = adStateOpen Then rsTD.Close
    Set rsTD = Nothing
    
    Exit Sub
EH:
     MsgBox Err.Description, vbCritical, g_strErrorLocation

End Sub


' 2009-02-05, JFW, Now in line with other shipments.
'
'Public Sub ShipTD()
'
'    Dim i As Integer
'    Dim ret As VbMsgBoxResult
'    Dim strReference As String
'    Dim strTrans As String
'    Dim colTags As Collection
'    Dim strMasterTrackingNbr As String
'    Dim intPieceCount As Long
'
'    On Error GoTo EH
'
'    g_strErrorLocation = "ShipTD"
'
'    If g_strTDOpenShip = "" Then
'        Beep
'        frmShip.StatusBar1.Panels(2) = "Choose a TD master..."
'        Set g_frmTD = New frmTD
'        g_frmTD.Show vbModeless, frmShip
'        Exit Sub
'    End If
'
'    If g_strTDOpenShip = "" Then
'        Beep
'        frmShip.StatusBar1.Panels(2) = "Choose a TD master..."
'        Exit Sub
'    End If
'
'    g_strErrorLocation = "modCustomButtons:CustomButton2_TDShip"
'
'    'Show Processing in status bar
'    frmShip.StatusBar1.Panels(2) = "Processing..."
'
'    'Disable all transaction buttons
'    Call frmShip.DisableButtons
'
'    intPieceCount = Val(frmShip.f116)
'    If Not g_rsMPS Is Nothing Then
'        If g_rsMPS.RecordCount > 0 Then
'            intPieceCount = g_rsMPS.RecordCount
'        End If
'    End If
'
'    If intPieceCount > 1 Then
'        frmShip.f3057 = Replace(frmShip.f3057, ", Pkg <n> of <m>", "")
'        frmShip.f3057 = Replace(frmShip.f3057, "Pkg <n> of <m>", "")
'    End If
'
'    'Assign the text fields to global vars
'    Call frmShip.AssignTextToGlobal
'
'    If intPieceCount > 1 Then
'        strReference = frmShip.f3057 & IIf(frmShip.f3057 <> "", ", ", "") & "Pkg <n> of <m>"
'    End If
'
'    Set colTags = New Collection
'    colTags.Add g_str24, "g_str24"
'    colTags.Add g_str11, "g_str11"
'    colTags.Add g_str12, "g_str12"
'    colTags.Add g_str13, "g_str13"
'    colTags.Add g_str15, "g_str15"
'    colTags.Add g_str16, "g_str16"
'    colTags.Add g_str17, "g_str17"
'    colTags.Add g_str50, "g_str50"
'    colTags.Add g_str25, "g_str25"
'    colTags.Add g_str1274, "g_str1274"
'    colTags.Add g_str116, "g_str116"
'    colTags.Add g_str1670, "g_str1670"
'    colTags.Add g_str3056, "g_str3056"
'    colTags.Add g_str1358, "g_str1358"
'    colTags.Add g_str118, "g_str118"
'
'    g_lngErrorCount = 0
'    g_lngShipCount = 0
'
'    strTrans = BuildTDShipTrans(g_str1, 1, strMasterTrackingNbr)
'
'    For g_lngShipCount = 1 To intPieceCount
'
'        ' 2006-10-05, JFW, Build package with shipment weight
'        If intPieceCount > 1 Then
'            TransactionStripTag strTrans, "116"
'            TransactionStripTag strTrans, "1670"
'            TransactionBuilder strTrans, "116", "1"
'            If frmShip.chkDuplicate.Value = 1 Then
'                TransactionBuilder strTrans, "1670", CLng(CDbl(g_str1670) * 100)
'            Else
'                TransactionBuilder strTrans, "1670", CLng(CDbl(g_str1670) * 100 / CDbl(g_str116))
'            End If
'
'            g_str3057 = strReference
'            g_str3057 = Replace(g_str3057, "<n>", g_lngShipCount)
'            g_str3057 = Replace(g_str3057, "<m>", intPieceCount)
'            TransactionStripTag strTrans, "3002"
'            TransactionStripTag strTrans, "3057"
'            TransactionBuilder strTrans, "3002", g_str3057
'            TransactionBuilder strTrans, "3057", g_str3057
'
'            strTrans = Replace(strTrans, "99,""""", "")
'            TransactionBuilder strTrans, 99, ""
'        End If
'
'        ' If MPS is used, then change the weight
'        If Not g_rsMPS Is Nothing Then
'            If g_rsMPS.RecordCount > 0 Then
'                g_rsMPS.AbsolutePosition = g_lngShipCount
'                TransactionStripTag strTrans, "21"
'                TransactionStripTag strTrans, "1670"
'                If IsNumeric(g_rsMPS!g_str1670) Then
'                    TransactionBuilder strTrans, "1670", CLng(CLng(CDbl(g_rsMPS!g_str1670) + 0.49999) * 100)
'                    g_str1670 = CLng(CDbl(g_rsMPS!g_str1670) + 0.49999)
'                Else
'                    TransactionBuilder strTrans, "1670", "100"
'                    g_str1670 = 1
'                End If
'                strTrans = Replace(strTrans, "99,""""", "")
'                TransactionBuilder strTrans, 99, ""
'                'f1  g_str1670   g_str57 g_str58 g_str59 g_str26 g_str25 g_str3056   g_str3057   g_str3018   ShipDate
'            End If
'        End If
'
'        If g_lngShipCount = 2 Then
'            strMasterTrackingNbr = g_str29
'        End If
'        If g_lngShipCount > 1 Then
'            TransactionStripTag strTrans, "77"
'            TransactionStripTag strTrans, "79"
'            TransactionBuilder strTrans, "79", "Package " & g_lngShipCount _
'                    & " of " & intPieceCount _
'                    & ", master tracking number " & strMasterTrackingNbr
'            TransactionStripTag strTrans, "80"
'            TransactionBuilder strTrans, "80", "CA"
'            TransactionStripTag strTrans, "81"
'            TransactionStripTag strTrans, "82"
'            TransactionBuilder strTrans, "82", "1"
'            TransactionStripTag strTrans, "83"
'            TransactionStripTag strTrans, "84"
'            TransactionStripTag strTrans, "414"
'            TransactionBuilder strTrans, "414", "EA"
'            TransactionStripTag strTrans, "1030"
'            TransactionBuilder strTrans, "1030", "00000010000"
'            TransactionStripTag strTrans, "119"
'            TransactionBuilder strTrans, "119", "001"
'
'            ' Remove email from additional pieces
'            TransactionStripTag strTrans, "1553"
'            TransactionStripTag strTrans, "1554"
'            TransactionStripTag strTrans, "1556"
'            TransactionStripTag strTrans, "1557"
'            TransactionStripTag strTrans, "1206"
'            TransactionStripTag strTrans, "1551"
'
'            strTrans = Replace(strTrans, "99,""""", "")
'            TransactionBuilder strTrans, 99, ""
'        End If
'
'        If g_blnAbortBatch Then
'            ret = MsgBox("Click OK to resume processing, click Cancel to abort processing.", vbOKCancel, "Batch Processing Paused")
'
'            If ret = vbOK Then
'                g_blnAbortBatch = False
'            Else
'                Exit For
'            End If
'        End If
'
'        'CIC defined routine that runs before shipping the package.
'        'Return True to continue shipment, False to Cancel.
'        If BeforeShip(strTrans) Then
'
'            ' 2007-05-15, JFW, New TD child path
'            'g_blnTD = True
'            g_blnTDChild = True
'            ' debugprint "ShipTD", g_blnTDChild
'            g_blnComplete = False
'
'            Call SendData(strTrans)
'
'            Do While Not g_blnComplete
'                DoEvents
'            Loop
'
'            If g_str3 <> "" Then
'                Exit For
'            End If
'        End If
'
'        g_str24 = colTags.item("g_str24")
'        g_str11 = colTags.item("g_str11")
'        g_str12 = colTags.item("g_str12")
'        g_str13 = colTags.item("g_str13")
'        g_str15 = colTags.item("g_str15")
'        g_str16 = colTags.item("g_str16")
'        g_str17 = colTags.item("g_str17")
'        g_str50 = colTags.item("g_str50")
'        g_str25 = colTags.item("g_str25")
'        g_str1274 = colTags.item("g_str1274")
'        g_str116 = colTags.item("g_str116")
'        g_str1670 = colTags.item("g_str1670")
'        g_str3056 = colTags.item("g_str3056")
'        g_str1358 = colTags.item("g_str1358")
'        g_str118 = colTags.item("g_str118")
'
'    Next g_lngShipCount
'
'    frmShip.SSTab1.Tab = 0
'
'    ClearShipScreen
'
'    Exit Sub
'EH:
'     MsgBox Err.Description, vbCritical, g_strErrorLocation
'
'End Sub


'---------------------------------------------------------------------------------------
' Module    : TDReply()
' DateTime  : 2/10/2005
' Author    : Chris Elwell
' Purpose   : Handle TD Replies. Moved out of ParseComplete.
'---------------------------------------------------------------------------------------
'
Public Sub TDReply()
    
    On Error GoTo EH
    'g_strErrorLocation = "frmShip:TDReply"
    
    g_blnTDInProgress = False
    
    If g_str3 = "An OpenShip Index (542) was not specified." Then
        If g_str1 = "TD MAWB CONFRM" _
        Or g_str1 = "TD MAWB DELETE" Then
            g_str3 = ""
        End If
    End If
    
'    If g_str3 = "The shipment must have a minimum of one package." Then
'        If g_str1 = "TD MAWB CONFRM" Then
'            g_str3 = ""
'        End If
'    End If
    
    If g_str3 = "" Then
        Select Case Left(g_str1, 15)
            'Create shipment
            Case "TD MAWB CREATE"
                Call SaveTDShipment(g_str29, True)
                Call g_frmTD.UpdateTDGrid("Open", g_frmTDAdd.f24)
                frmShip.StatusBar1.Panels(2) = "TD MAWB Created"
                g_strTDMasterTrkNbr = g_str29
                
                g_clsReg.SetRegistryValue "TDMasterShipmentID", g_strTDMasterTrkNbr, REG_SZ
                g_clsReg.SetRegistryValue "TDMasterShipmentDate", Format(g_dteTDDate, "yyyy-mm-dd"), REG_SZ
                g_clsReg.SetRegistryValue "TDOpenShipIndex", g_strTDOpenShip, REG_SZ
                            
                On Error Resume Next
                Unload g_frmTDAdd
                Set g_frmTDAdd = Nothing
                On Error GoTo EH
                
            'Delete shipment
            Case "TD MAWB DELETE"
                Call ChangeTDStatus(g_strTDMasterTrkNbr, "Deleted")
                If Not g_frmTD Is Nothing Then
                    Call g_frmTD.UpdateTDGrid("Deleted", g_frmTD.f24)
                End If
                frmShip.StatusBar1.Panels(2) = "TD MAWB Deleted"
                g_strTDMasterTrkNbr = ""
                g_strTDOpenShip = ""
                
                g_clsReg.SetRegistryValue "TDMasterShipmentID", g_strTDMasterTrkNbr, REG_SZ
                g_clsReg.SetRegistryValue "TDMasterShipmentDate", Format(g_dteTDDate, "yyyy-mm-dd"), REG_SZ
                g_clsReg.SetRegistryValue "TDOpenShipIndex", g_strTDOpenShip, REG_SZ

            'Confirm shipment
            Case "TD MAWB CONFRM"
                Call ChangeTDStatus(g_str1123, "Confirmed")
                If Not g_frmTD Is Nothing Then
                    Call g_frmTD.UpdateTDGrid("Confirmed", g_frmTD.f24)
                End If
                frmShip.StatusBar1.Panels(2) = "TD MAWB Confirmed"
                g_strTDMasterTrkNbr = ""
                g_strTDOpenShip = ""
                On Error Resume Next
                Unload g_frmTDAdd
                Set g_frmTDAdd = Nothing
                On Error GoTo EH

                g_clsReg.SetRegistryValue "TDMasterShipmentID", g_strTDMasterTrkNbr, REG_SZ
                g_clsReg.SetRegistryValue "TDMasterShipmentDate", Format(g_dteTDDate, "yyyy-mm-dd"), REG_SZ
                g_clsReg.SetRegistryValue "TDOpenShipIndex", g_strTDOpenShip, REG_SZ
            
            'Delete shipment
            Case "TD TDC DELETE"
                Call ChangeTDCStatus(g_str29)
                Call WriteDelete(g_str29)
                frmShip.StatusBar1.Panels(2) = "TD master " & g_str29 & " deleted"
                If g_blnDeletesComplete Then
                    ' frmMsgBox.ShowMessage "See frmShip ship history.", 10000
                    Call frmShip.UpdateShipmentsGrid(frmShip.cboShipmentType, frmShip.cboShipmentStatus)
                    Call frmShip.SetTrackButtons
                End If
            
                g_clsReg.SetRegistryValue "TDMasterShipmentID", g_strTDMasterTrkNbr, REG_SZ
                g_clsReg.SetRegistryValue "TDMasterShipmentDate", Format(g_dteTDDate, "yyyy-mm-dd"), REG_SZ
                g_clsReg.SetRegistryValue "TDOpenShipIndex", g_strTDOpenShip, REG_SZ
            
            ' 2007-05-15, JFW, No longer used for TD child, see SaveShipment
            'Add TDC
            Case Else
                ' 2006-11-07, JFW, Required here.
                If frmShip.cboCustID.Visible = True And frmShip.chkAddAddress = 1 Then
                    ' 2007-11-05, JFW, Sanofi, large AddressBook, test for Save and reload combos only if true
                    If frmShip.SaveAddress(frmShip.cboCustID) Then
                        Call LoadAddrLookupCombos(frmShip.cboCustID, frmShip.cboCustID, "CustID")
                        Call LoadAddrLookupCombos(frmShip.cboContact, frmShip.cboContact, "f12")
                        Call LoadAddrLookupCombos(frmShip.cboCompany, frmShip.cboContact, "f11")
                    End If
                End If
                                    
                Call SaveTDCShipment(g_str29, False, g_str1123)
                
                Call WriteReply
                
                ' 2009-02-06, JFW, Only after child.
                Call frmShip.ClearShipFields
                Call ClearGlobalVars
                Call frmShip.SetLogo
                
                frmShip.StatusBar1.Panels(2) = "Shipment Complete"
        End Select
        
        ' 2009-02-06, JFW, Not here, only after shipment.
        '        Call frmShip.ClearShipFields
        '        Call ClearGlobalVars
        '        Call frmShip.SetLogo
    
    Else
        Call WriteError
        frmShip.StatusBar1.Panels(2) = "Shipment Error"
    End If
    'Make sure the TD flag is set to the correct boolean value
    
    Exit Sub
EH:
    MsgBox Err.Description, vbCritical, "frmShip:TDReply"

End Sub

